/*
    Managed    ResourceBundle placed in contextmenu
    Created by S Kulkarni
*/

		import flash.net.URLRequest; 
		import flash.net.navigateToURL;
		import flash.ui.ContextMenuItem;
		
		import mx.controls.Alert;
		import mx.resources.ResourceBundle;

		[ResourceBundle("version")]
		private static var versionRB:ResourceBundle;

		private var versionItem:ContextMenuItem;
		private var companyItem:ContextMenuItem;
		private var debugItem:ContextMenuItem;
		private var websiteItem:ContextMenuItem;

		private var testItem:ContextMenuItem;

		import mx.managers.PopUpManager;
		import mx.core.Application;
		import mx.events.IndexChangedEvent;
		import mx.controls.Alert;
		import mx.collections.ArrayCollection;
		import mx.charts.events.ChartItemEvent;
		import mx.printing.*
		
		import pt.co.ptraco.debug_version.VersionDetailsPopup;
		import pt.co.ptraco.debug_version.DebugPopup;
		import mx.collections.GroupingCollection;
		import mx.collections.Grouping;
		import mx.collections.GroupingField;
		import pt.co.ptraco.debug_version.DebugInstance;
		
		public var pop2: VersionDetailsPopup;
		public var pop3: DebugPopup;
		



override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
	super.updateDisplayList(unscaledWidth, unscaledHeight);
	
	if(versionItem == null){
		this.versionItem = new ContextMenuItem("Version: "+versionRB.getString("version"), true, true);
		this.contextMenu.customItems.push(this.versionItem);
		this.versionItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, this.showVersionDetails);
		
		var debugTest:String =versionRB.getString("debugOn");
		if(debugTest =="true"){
			this.debugItem= new ContextMenuItem("Project Debug Item:", true, true);
			this.contextMenu.customItems.push(this.debugItem);
			this.debugItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, this.showDebugDetails);
		}
		
		this.companyItem = new ContextMenuItem("Company: "+versionRB.getString("company"), false, false);
		this.contextMenu.customItems.push(this.companyItem);
		
		this.websiteItem = new ContextMenuItem(versionRB.getString("type"), false, true);
		this.contextMenu.customItems.push(this.websiteItem);
		this.websiteItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, this.openWebsite);
		
	  	this.contextMenu.hideBuiltInItems();
	}
}

private function openWebsite(event:ContextMenuEvent):void{
	var u:URLRequest = new URLRequest("Release_notes_IT-01.html");
			navigateToURL(u,"_blank");
	//navigateToURL(new URLRequest("Release_notes_IT-01.html", "_blank");
}

private function showVersionDetails(event:ContextMenuEvent):void{
		openVersionDetails();
	}


private function showDebugDetails(event:ContextMenuEvent):void{
		openDebugWindow();
	}
	
   private function openVersionDetails():void{
            	
				pop2 = VersionDetailsPopup(
                PopUpManager.createPopUp(this, VersionDetailsPopup, true));
                pop2.title="Version Details";
                pop2.showCloseButton=true;
                pop2.popText.text = versionRB.getString("details");
                PopUpManager.centerPopUp(pop2);
				  
	}

	private function groupFunction(DebugGroupCollection:ArrayCollection):GroupingCollection{
							var mygroup:GroupingCollection=new GroupingCollection();
							  mygroup.source = DebugGroupCollection;
							  var group:Grouping= new Grouping();
							  var gf:GroupingField= new GroupingField("type");
	  						 group.fields = [gf];
							  mygroup.grouping = group;
							  mygroup.refresh();
							  return mygroup; 

	}
				
	private function openDebugWindow():void{
				pop3 = DebugPopup(
                PopUpManager.createPopUp(this, DebugPopup, false));
                pop3.title="Debug Details";
                pop3.showCloseButton=true;
                pop3.popText.text = DebugInstance.instance.mainLogText; 
                pop3.debugData = DebugInstance.instance.dubugArrayCollection;
                pop3.debugDG.dataProvider = groupFunction(DebugInstance.instance.dubugArrayCollection);
				pop3.debugDG.validateNow();
				
	}
	
	
	
